Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BD-24] [TNL-7318] BB-2355: Add LTI support and Django authentication extension. #105

Merged

Conversation

giovannicimolin
Copy link
Contributor

@giovannicimolin giovannicimolin commented Sep 15, 2020

This PR adds an authentication class that's used by LTI extensions to check the JWT token and a Django router for LTI related viewsets.
Also includes a small fix (includes iss in LTI payload message).

Testing instructions::

  1. Checkout this branch.
  2. Install requirements.
  3. Make sure quality checks and tests are running properly.
  4. There's no APIs using this currently, but it's well covered in tests.

Notes:
Split from #92 since it ended up growing too much.

Reviewers:

@openedx-webhooks openedx-webhooks added blended PR is managed through 2U's blended developmnt program needs triage labels Sep 15, 2020
@openedx-webhooks
Copy link

Thanks for the pull request, @giovannicimolin! I've created BLENDED-590 to keep track of it in Jira. More details are on the BD-24 project page.

When this pull request is ready, tag your edX technical lead.

@coveralls
Copy link

Coverage Status

Coverage decreased (-97.9%) to 0.0% when pulling 31161bd on open-craft:giovanni/bb-2355-add-endpoint-support into bbd55a4 on edx:master.

@coveralls
Copy link

coveralls commented Sep 15, 2020

Coverage Status

Coverage increased (+0.07%) to 97.992% when pulling d7e08ff on open-craft:giovanni/bb-2355-add-endpoint-support into bbd55a4 on edx:master.

Copy link
Contributor

@nedbat nedbat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some initial nits as I learn my way around.

raise exceptions.AuthenticationFailed(msg)

# Passing parameters back to the view through the request.
# Not exactly optimal.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to know more about this comment....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll improve the comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nedbat Is it better now?

Copy link
Contributor

@viadanna viadanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giovannicimolin I've read through the code and left a question on the passing the LTI configuration back to the view.
I also tested it locally and it's looking good.

@giovannicimolin
Copy link
Contributor Author

@viadanna @nedbat Ready for another review pass.

Copy link
Contributor

@viadanna viadanna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one missing nit, otherwise good to go 👍

  • I read through the code.

Since the base implementation of this library uses JWT tokens, we expect
a RSA256 signed token that contains the allowed scopes.
"""
keyword = 'Bearer'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
keyword = 'Bearer'
KEYWORD = 'Bearer'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've based this class on https://github.com/encode/django-rest-framework/blob/master/rest_framework/authentication.py#L148 which uses a lowercase variable. I don't see any issue changing it to uppercase though.

Do you want me to change it?

lti_config_id = request.parser_context['kwargs'].get('lti_config_id')

# Check if auth token is present on request and is correctly formatted.
if not auth or auth[0].lower() != self.keyword.lower():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not auth or auth[0].lower() != self.keyword.lower():
if not auth or auth[0].lower() != self.KEYWORD.lower():

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blended PR is managed through 2U's blended developmnt program merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants